<!DOCTYPE html>
<!--
 * Copyright (c) 2010 The Chromium Authors. All rights reserved.  Use of this
 * source code is governed by a BSD-style license that can be found in the
 * LICENSE file.
-->
<html>
<head>

</head>
<body>
	<script>
		/**
		 * Returns a handler which will open a new window when activated.
		 */
		function getClickHandler() {
			return function(info, tab) {
				chrome.tabs.executeScript(tab.id, function() {
					alert(document.body.innerHTML);
				}, function() {
					alert('success');
				})
              /* The srcUrl property is only available for image elements.*/
              /*           var url = 'info.html#' + info.srcUrl;*/
				var url = 'info.html#' + tab.url;
				alert(document.body.innerHTML);
           /* Create a new window to the info page.*/
           /*chrome.windows.create({ url: url, width: 520, height: 660 });*/
			};
		};
		function getClickHandler2() {
			return function(info, tab) {
/* 				chrome.tabs.executeScript(tab.id, function() {
 					alert(document.body.innerHTML);
				}, function() {
            alert('success');
         })*/
           /* The srcUrl property is only available for image elements.*/
				           var url = 'info.html#' + info.srcUrl;
				var url = 'generate.html#' + tab.url;
           /*alert(document.body.innerHTML);*/
           /* Create a new window to the info page.*/
				chrome.windows.create({ url: url, width: 520, height: 660 });
			};
		};
		/**
		 * Create a context menu which will only show up for images.
		 */
/* 		chrome.contextMenus.create({
  			"title" : "Analysis Books",
  			"type" : "normal",
  			"contexts" : [ "all" ],
  			"onclick" : getClickHandler()
       		});*/
		chrome.contextMenus.create({
			"title" : "Generate Books",
			"type" : "normal",
			"contexts" : [ "all" ],
			"onclick" : getClickHandler2()
		});
	

function genericOnClick(info, tab) {
	 
	window.open("https://www.google.com/search?tbm=bks&tbo=1&btnG=&q="+info.selectionText+"")
	console.log("item " + info.menuItemId + " was clicked");
	console.log("info: " + JSON.stringify(info));
	console.log("tab: " + JSON.stringify(tab));
}
var contexts = ["selection","editable"];
for ( var i = 0; i < contexts.length; i++) {
	var context = contexts[i];
	var title = "Search '" + context + "' in google book";
	var id = chrome.contextMenus.create({
		"title" : title,
		"contexts" : [ context ],
		"onclick" : genericOnClick
	});
	console.log("'" + context + "' item:" + id);
}
</script>
</body>
</html>